<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Alterar atividade extra-classe</title>
        <script type="text/javascript" src="../js/jquery.js" ></script>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js" ></script>
        <script type="text/javascript" src="../js/jquery.ui.datepicker-pt-BR.js" ></script>
        <script type="text/javascript" src="../js/forms.js"></script>
        <link rel="stylesheet" href="../css/ui-lightness/jquery-ui-1.8.2.custom.css">
        <link rel="stylesheet" href="../css/forms.css">
    </head>
    <script>$(document).ready(function(){
        $("#form").validate({
            rules: {
                matricula: {required: true}
                ,id_tipoafastamento: {required: true,digits: true
                }
                ,desc_afastamento: {required: true}
                ,data_inicio: {required: true}
                ,data_fim: {required: true}
                ,data_validado: {}
                ,situacao_afastamento: {}
                ,carga_horaria: {digits: true
                }
                ,id_setor_solicitante: {digits: true
                }
            },
            submitHandler: function(form) {
                salvar(form);
            }
        });
    });

    $(function() {
        $("#data_inicio").datepicker();
        $("#data_fim").datepicker();

    });
    </script>


    <body>
     
        <form name="form" id="form" method="post" action="update.jsp" >
                <fieldset><legend>Dados</legend>
                    <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
                        SELECT  * FROM Afastamentos where id_afastamento=?
                        <sql:param value="${param.chave}"/>
                    </sql:query>
                    <c:forEach var="row" items="${query.rows}">
                        <input type="hidden" name="id_afastamento" size="10" maxlength="10" class="required" value="${row.id_afastamento}">
                        <input type="hidden" id="matricula"  name="matricula" size="6" maxlength="6" class="required" value="${row.matricula}">
                        <p><label class="lbInput">Tipo<em>*</em></label>
                            <sql:query var="queryTipo" dataSource="jdbc/dbo_MicrosoftSQLServer">
                                SELECT  * FROM TipoAfastamento
                                order by desc_tipoafastamento
                            </sql:query>
                            <select name="id_tipoafastamento" class="required" >
                                <c:forEach var="rowTipo" items="${queryTipo.rows}">
                                    <option value="${rowTipo.id_tipoafastamento}" ${rowTipo.id_tipoafastamento==row.id_tipoafastamento?'selected':''}>${rowTipo.desc_tipoafastamento}</option>
                                </c:forEach>
                            </select>
                        </p>
                        <p><label class="lbInput">Descrição<em>*</em></label>
                            <textarea name="desc_afastamento" class="required" rows="5" cols="50" class="required" >${row.desc_afastamento}</textarea>
                        </p>

                        <fmt:formatDate var="data_inicio" value="${row.data_inicio}" pattern="dd/MM/yyyy"/>
                        <fmt:formatDate var="data_fim" value="${row.data_fim}" pattern="dd/MM/yyyy"/>

                        <p><label class="lbInput">Início<em>*</em></label>
                            <input type="text" id="data_inicio" name="data_inicio" size="10" maxlength="10" class="required" value="${data_inicio}">
                        </p>
                        <p><label class="lbInput">Fim<em>*</em></label>
                            <input type="text" id="data_fim" name="data_fim" size="10" maxlength="10" class="required" value="${data_fim}">
                        </p>

                        <p><label class="lbInput">Área solicitante</label>
                            <sql:query var="querySetor" dataSource="jdbc/dbo_MicrosoftSQLServer">
                                SELECT  * FROM Setores
                                order by desc_setor
                            </sql:query>
                            <select name="id_setor_solicitante">
                                <option value="">Não se aplica</option>
                                <c:forEach var="rowSetor" items="${querySetor.rows}">
                                    <option value="${rowSetor.id_setor}" ${rowSetor.id_setor == row.id_setor_solicitante?'selected':''}>${rowSetor.desc_setor}</option>
                                </c:forEach>
                            </select>
                        </p>
                        <p><label class="lbInput">Carga Horária</label>
                            <input type="text" name="carga_horaria" size="10" maxlength="10" value="${row.carga_horaria}">
                        </p>

                    </c:forEach><p>
                        <input class="submit" type="submit" value="Salvar">
                        <input class="submit" type="button" value="Listar" onclick="listar('fm_lista_Afastamentos.jsp')">
                    </p>
                    <div id="ajax_dados" style="display:block">
                    </div>
                    <div id="msg" style="display:none"></div>
                </fieldset>
        <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>
    </body>
</html>
